<?php
namespace Ticket\Form;

use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
use \Zend\Form\Form;
use Zend\InputFilter\Factory as InputFactory;
use Zend\InputFilter\InputFilter;

class TicketUpdateFormFactory implements FactoryInterface {
    public function createService(ServiceLocatorInterface $serviceLocator) {
        $form = new Form('ticket');
        $form->setAttribute('method', 'post');
        
        $form->add(array(
            'name' => 'text',
            'type' => 'textarea',
            'options' => array(
                'label' => 'Text',
            ),
        ));
        
        $form->add(array(
            'name' => 'submit',
            'type' => 'submit',
            'attributes' => array(
                'value' => 'Add Update',
                'id' => 'submitbutton',
            ),
        ));
        
        $inputFilter = $this->createFilter($serviceLocator);
        $form->setInputFilter($inputFilter);
        
        $form->setHydrator(new \Zend\Stdlib\Hydrator\ClassMethods(false));

        return $form;
    }
    
    public function createFilter(ServiceLocatorInterface $serviceLocator) {
        $inputFilter = new InputFilter();
        $factory = new InputFactory();
        
        $inputFilter->add($factory->createInput(array(
                    'name' => 'text',
                    'required' => true,
                    'filters' => array(
                        array('name' => 'StripTags'),
                        array('name' => 'StringTrim'),
                    ),
                    'validators' => array(
                        array(
                            'name' => 'StringLength',
                            'options' => array(
                                'encoding' => 'UTF-8',
                                'min' => 1,
                                'max' => 2000, // TODO: SYNCHRONIZE
                            ),
                        ),
                    ),
        )));
        
        return $inputFilter;
    }
}